#include "fig_pickup_collection.h"




FIGPickupCollection::FIGPickupCollection(FIGPickup::PICKUP_TYPES Type )
{

}
	
FIGPickupCollection::~FIGPickupCollection()
{
	Clear();
}

void		FIGPickupCollection::Render(const math::Vec2& Offset,float Scale)
{
	for(unsigned int i = 0; i < m_Pickups.size(); i++)
	{
		FIGPickup*  pPickup = m_Pickups[i];
		pPickup->Render(Offset,Scale);
	}
}

void		FIGPickupCollection::RenderShadow(const math::Vec2& Offset,float Scale)
{
	for(unsigned int i = 0; i < m_Pickups.size(); i++)
	{
		FIGPickup*  pPickup = m_Pickups[i];
		pPickup->RenderShadow(Offset,Scale);
	}
}
	
void		FIGPickupCollection::RenderDebug(const math::Vec2& Offset,float Scale)
{
	for(unsigned int i = 0; i < m_Pickups.size(); i++)
	{
		FIGPickup*  pPickup = m_Pickups[i];
		pPickup->RenderDebug(Offset,Scale);
	}
}

void		FIGPickupCollection::Tick(float dt)
{
	for(unsigned int i = 0; i < m_Pickups.size(); i++)
	{
		FIGPickup*  pPickup = m_Pickups[i];
		pPickup->Tick(dt);
	}
}


void		FIGPickupCollection::Clear()
{
	for(unsigned int i = 0; i < m_Pickups.size(); i++)
	{
		FIGPickup*  pPickup = m_Pickups[i];
		pPickup->Clear();
		UTIL_SAFE_DELETE(pPickup);
	}
	m_Pickups.resize(0);
}

void		FIGPickupCollection::Spawn(FIGPickup::PICKUP_TYPES Type , const math::Vec2& P )
{
	
	bool	bSpawn =false;
	FIGPickup*  pObj;
	
	pObj = NULL;
	bSpawn =false;
	for( int i = 0; i < (int)m_Pickups.size(); i++)
	{
		pObj = m_Pickups[i];
		if(!pObj->IsAlive())
		{
			
			bSpawn = true;
			i = (int)m_Pickups.size();
		}
	}

	if(!bSpawn)
	{
		
		pObj = CreatePickup(Type , P);
		if(pObj)
			m_Pickups.push_back(pObj);    			
		
	}

	if(pObj)
		pObj->ReSpawn();
	
	
}



FIGPickup*		FIGPickupCollection::GetPickupByIndex(int Index)
{
	return NULL;
}

bool			FIGPickupCollection::HitTest(const math::Vec2& P)
{
	return false;
}

FIGPickup*		FIGPickupCollection::CreatePickup(FIGPickup::PICKUP_TYPES Type, const math::Vec2& P)
{
	return new FIGPickup(Type,P);
}